package com.cjw.controller.resourceManage;

import com.cjw.config.annotation.OperationLogAnnotation;
import com.cjw.pojo.dto.database.PageDTO;
import com.cjw.pojo.dto.systemManage.ExamineDTO;
import com.cjw.pojo.entity.resourceManage.ControllerResource;
import com.cjw.pojo.query.resourceManage.AddController;
import com.cjw.pojo.query.resourceManage.QueryListController;
import com.cjw.pojo.query.systemManage.ExamineQuery;
import com.cjw.service.resourceManage.ControllerResourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author : cjw
 * @date: : 2022/3/6 22:21
 * @description : some
 */
@RestController
@RequestMapping("/admin/contrResource")
@Api("接口资源")
public class ContrResourceController {
    @Autowired
    private ControllerResourceService resourceService;

    @PostMapping("/findList")
    @ApiOperation("查看全部接口")
    @OperationLogAnnotation(operModul = "资源管理-后端安全管理",operType = "查看全部审核记录",operDesc = "查询")
    public PageDTO<List<ControllerResource>> findListController(@RequestBody QueryListController queryListController) {
        return resourceService.findListController(queryListController);
    }

    @PostMapping("/add")
    @ApiOperation("添加接口")
    @OperationLogAnnotation(operModul = "资源管理-后端安全管理",operType = "添加接口",operDesc = "添加")
    public Boolean addController(@RequestBody @Valid AddController addController) {
        return resourceService.addController(addController);
    }

    @PostMapping("/update")
    @ApiOperation("修改接口")
    @OperationLogAnnotation(operModul = "资源管理-后端安全管理",operType = "修改接口",operDesc = "添加")
    public Boolean updateController(@RequestBody @Valid AddController addController) {
        return resourceService.updateController(addController);
    }

    @PostMapping("/close")
    @ApiOperation("关闭接口")
    @OperationLogAnnotation(operModul = "资源管理-后端安全管理",operType = "关闭接口",operDesc = "修改")
    public Boolean closeController(Long id) {
        return resourceService.changeControllerState(id,1);
    }

    @PostMapping("/open")
    @ApiOperation("打开接口")
    @OperationLogAnnotation(operModul = "资源管理-后端安全管理",operType = "打开接口",operDesc = "修改")
    public Boolean openController(Long id) {
        return resourceService.changeControllerState(id,0);
    }

    @GetMapping("/detail")
    @ApiOperation("获取详情接口")
    @OperationLogAnnotation(operModul = "资源管理-后端安全管理",operType = "打开接口",operDesc = "修改")
    public ControllerResource detailController(Long id) {
        return resourceService.detail(id);
    }
}
